<?php
namespace app\index\controller;

use think\Config;
use think\Db;

class Alitrade
{
    public function aliPay()
    {
        vendor("alipay.AopSdk");

        $aop = new \AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = config('pay.ali_appid');
        $aop->rsaPrivateKey = config('pay.ali_key');
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        $request = new \AlipayTradeQueryRequest();
        $request->setBizContent("{" .
            "\"out_trade_no\":\"".$_GET['out_trade_no'] ."\"," .
            "\"trade_no\":\"\"," .
            "\"org_pid\":\"\"" .
            "  }"); //CTV15373465429412
        $result = $aop->execute ( $request);
        $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
        $resultCode = $result->$responseNode->code;
        if(!empty($resultCode)&&$resultCode == 10000){
            $re=array(
                'status'=>200,
                "msg" => "请求成功!",
                "data"=>array(
                    "out_trade_no"=> $_GET['out_trade_no'],
                    "alipay_trade_status"=>"WAIT_BUYER_PAY"
                )
            );
            return json_encode($re);
        } else {
            $re=array(
                'status'=>400,
                "msg" => "查询失败",
            );
            return json_encode($re);
        }

    }
}



